# v0.2-test.py 
import unittest
from main import count_chars, count_words, count_sentences

class TestWordCounter(unittest.TestCase):
    """
    对 v0.2 版本的核心统计函数进行深入和高难度的边界情况测试，
    以确保各模块函数在各种边界和特殊情况下的行为正确。
    """

    #1.字符统计
    def test_character_count_advanced(self):
        """测试字符统计，覆盖特殊字符和编码问题"""
        self.assertEqual(count_chars("hello"), 5, "msg='基本字符串统计失败'")
        self.assertEqual(count_chars(""), 0, "msg='空字符串长度应为0'")
        #难度用例1
        self.assertEqual(count_chars("\n\t\r "), 4, "msg='应能正确计算所有类型的空白符'")
        #难度用例2
        self.assertEqual(count_chars("`~!@#$%^&*()-_=+[]{}|;:'\",<.>/?"), 31, "msg='应能正确计算所有标准标点符号'")

    #2.单词统计
    def test_word_count_advanced(self):
        """测试单词统计，覆盖各种复杂的空白和分隔情况"""
        self.assertEqual(count_words("hello world"), 2, "msg='基本单词统计失败'")
        self.assertEqual(count_words(" \n\t \r "), 0, "msg='纯空白字符串不应包含单词'")
        #难度用例1
        self.assertEqual(count_words("word1\nword2\tword3\rword4"), 4, "msg='应能处理多种空白符作为单词分隔'")
        #难度用例2
        self.assertEqual(count_words("   leading   and   trailing   spaces   "), 4, "msg='应能正确处理大量且不规则的空格'")
        #难度用例3
        self.assertEqual(count_words("word-with-hyphen, separated by comma."), 4, "msg='split()应能正确处理带标点的字符串'")

    #3.句子统计
    def test_sentence_count_advanced(self):
        """测试句子统计，覆盖各种棘手的标点组合"""
        self.assertEqual(count_sentences("A simple sentence."), 1, "msg='基本句子统计失败'")
        self.assertEqual(count_sentences("A line without end mark"), 0, "msg='没有标点的行不应算作句子'")
        #难度用例1
        self.assertEqual(count_sentences("What?! Is this real..."), 2, "msg='应能正确处理多种标点符号'")
        #难度用例2
        self.assertEqual(count_sentences("The file ends right now!"), 1, "msg='应能处理以标点结尾的文本'")
        #难度用例3
        self.assertEqual(count_sentences("First line.\nSecond line?"), 2, "msg='应能识别以换行符分隔的句子'")

if __name__ == '__main__':
    # 终端命令：python -m unittest -v test.py
    unittest.main()